import React from 'react';

export class App extends React.Component {
  constructor() {
    super();
    this.inputRef = React.createRef();
  }

  handleSubmit = () => {
    console.log(this.inputRef.current);
    console.log(this.inputRef.current.value);
    // 没办法通过标签属性控制焦点
    this.inputRef.current.focus();
  };

  render() {
    return (
      <div>
        <input type="text" ref={this.inputRef} />
        <button onClick={this.handleSubmit}>提交</button>
      </div>
    );
  }
}
